<?php
    class Form_Dangtin extends Zend_Form
    {
        public function init()
        {
            $this->clearDecorators();
            $decorators=  array(array('ViewHelper'),array('Errors'),array('Label',array('class'=>'leftalign')),array('HtmlTag'));
            $this->setMethod('post')
                    ->setAttrib('enctype','multipart/form-data','UTF-8');
            //ma the loai
            $idtl=  $this->createElement("text","idtl",array(
                                                                "size"=>30,
                                                                "label"=>"Ma The Loai:"
            ));
            $this->addElement($idtl);
            $idtl=  $this->getElement('idtl')
                        ->setRequired(true)
                        ->addValidator('NotEmpty')
                        ->addValidator('alnum')
                        ->addFilter('StringTrim');
          //  $idtl->getValidator('anum')->setMessage('Ma the loai phai la so');
            $idtl->getValidator('NotEmpty')->setMessage('Ma the loai ko dx bo trong');
            $idtl->setDecorators(array(
                                        'ViewHelper',
                                        'Description',
                                        'Errors',   
                                        array(array('data'=>'HtmlTag'),array('tag'=>'td')),
                                        array('Label',array('tag'=>'td')),
					array(array('row'=>'HtmlTag'),array('tag'=>'tr'))
                ));           
                $idtl = new Model_Theloai;
		$all = $idtl->getAll();
		$arr = array();
		$arr['all']="Tất cả";	

		foreach($all as $item)
		{
			$arr[$item['idtl']] = $item['tentheloai'];
		}
           $idtl=$this->createElement("select", "idtl", array(
						"label"=>"The Loai",
						"multioptions"=>$arr
			));
            $this->addElement($idtl);
            //ma loai tin
                $idlt = new Model_Loaitin();
		$all = $idlt->getAll();
		$arr = array();

		$arr['all']="Tất cả";	

		foreach($all as $item)
		{
			$arr[$item['idlt']] = $item['tenloaitin'];
		}
           $id=$this->createElement("select", "idlt", array(
						"label"=>"Loai Tin",
						"multioptions"=>$arr
			));
            $this->addElement($id);
            //ten tieude
		$tieude=$this->createElement("text","tieude",array(
														"size"=>30,
														"label"=>"Tieu De :"));
		$this->addElement($tieude);
		$tieude = $this->getElement('tieude')
						->setRequired(true)
						->addValidator('NotEmpty')
						->addValidator('alnum')
						->addFilter('StringTrim');
                
               
                
		//$tieude->getValidator('alnum')->setMessage('Ten tieu phai la so va chu');
		$tieude->getValidator('NotEmpty')->setMessage('Ten tieu de khong duoc bo trong');
		$tieude->setDecorators(array(
									   'ViewHelper',
									   'Description',
									   'Errors',
									   array(array('data'=>'HtmlTag'),array('tag'=>'td')),
									   array('Label',array('tag'=>'td')),
									   array(array('row'=>'HtmlTag'),array('tag'=>'tr'))
									   ));
                //tom tat
		$tomtat=$this->createElement("text","tomtat",array(
														"size"=>30,
														"label"=>"Tom Tat :"));
		$this->addElement($tomtat);
		$tomtat = $this->getElement('tomtat')
						->setRequired(true)
						->addValidator('NotEmpty')
						->addValidator('alnum')
						->addFilter('StringTrim');
		//$tomtat->getValidator('alnum')->setMessage('Tom tat la so va chu');
		$tomtat->getValidator('NotEmpty')->setMessage('Tom tat khong duoc bo trong');
		$tomtat->setDecorators(array(
									   'ViewHelper',
									   'Description',
									   'Errors',
									   array(array('data'=>'HtmlTag'),array('tag'=>'td')),
									   array('Label',array('tag'=>'td')),
									   array(array('row'=>'HtmlTag'),array('tag'=>'tr'))
									   ));
                //noi dung
		$noidungtin = $this->createElement("textarea", "noidungtin", array(
													"cols"=>"15",
													"rows"=>"30",
													"label"=>"Noi dung tin :",
													"class"=>"ckeditor",
													"id"=>"noidungtin"
												));
		$this->addElement($noidungtin);
		$noidungtin->setDecorators(array(
									   'ViewHelper',
									   'Description',
									   'Errors',
									   array(array('data'=>'HtmlTag'),array('tag'=>'td')),
									   array('Label',array('tag'=>'td')),
									   array(array('row'=>'HtmlTag'),array('tag'=>'tr'))
									   ));
                //Hinh
                $hinhnho=$this->createElement("file","hinhnho",array(
														"label"=>"Hinh nho :"));
		$this->addElement($hinhnho);
		$hinhnho->setDecorators(array(
									   'File',
									   'Description',
									   'Errors',
									   array(array('data'=>'HtmlTag'),array('tag'=>'td')),
									   array('Label',array('tag'=>'td')),
									   array(array('row'=>'HtmlTag'),array('tag'=>'tr'))
									   ));
                //ngay nhap
		$ngaycapnhat = $this->createElement("text", "ngaycapnhat", array(
													"size"=>30,
													"label"=>"Ngay cap nhat :",
													"id"=>"ngaycapnhat"
												));
		$this->addElement($ngaycapnhat);
		$ngaycapnhat->setDecorators(array(
									   'ViewHelper',
									   'Description',
									   'Errors',
									   array(array('data'=>'HtmlTag'),array('tag'=>'td')),
									   array('Label',array('tag'=>'td')),
									   array(array('row'=>'HtmlTag'),array('tag'=>'tr'))
									   ));
		//button luu
		$b=$this->createElement("submit","Luu");
		$this->addElement($b);
		$b->setDecorators(array(
									   'ViewHelper',
									   'Description',
									   'Errors',
									   array(array('data'=>'HtmlTag'),array('tag'=>'td','colspan'=>'2','align'=>'center')),
									   array(array('row'=>'HtmlTag'),array('tag'=>'tr'))
									   ));
		$this->setDecorators(array(
								   'FormElements',
								   array(array('data'=>'HtmlTag'),array('tag'=>'table')),'Form'));
        }   
      
    }
                
?>
